﻿using BattleBotsMattAndSunny.Components.Interfaces;
using BattleBotsMattAndSunny.Utilities;
using Robocode;
using Robocode.Util;

namespace BattleBotsMattAndSunny.Components.Guns
{
    public class TurningGunner : IGunManager
    {
        private AdvancedRobot robot { get; set; }

        private IDataManager dataManager { get; set; }

        public TurningGunner(IDataManager dm, AdvancedRobot r)
        {
            dataManager = dm;
            robot = r;
        }

        public void OnScannedRobot(ScannedRobotEvent e, double power)
        {
            double radarTurn =
                // Absolute bearing to target
       robot.HeadingRadians + e.BearingRadians
                // Subtract current radar heading to get turn required
       - robot.GunHeadingRadians;

            robot.TurnRightRadians(Utils.NormalRelativeAngle(radarTurn));

            Fire(power);
        }

        public void Fire(double power)
        {
            dataManager.StoreBullet(robot.SetFireBullet(power));
            //robot.Execute();
        }

        public void Move()
        {
            //robot.TurnGunRight(double.PositiveInfinity);
        }
    }
}